package com.itheima.tlias84.utils;

import lombok.Data;

@Data
public class ResultUtil {
    private Integer code;
    private String msg;
    private Object data;

    private ResultUtil() { }

    /**
     * 默认成功方法
     * @return
     */
    public static ResultUtil success() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = "success";
        return resultUtil;
    }

    /**
     * 携带自定义成功信息返回的方法
     * @param message
     * @return
     */
    public static ResultUtil success(String message) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = message;
        return resultUtil;
    }

    /**
     * 携带数据返回的方法
     * @param data
     * @return
     */
    public static ResultUtil success(Object data) {
        ResultUtil resultUtil = success();
        resultUtil.data = data;
        return resultUtil;
    }

    /**
     * 携带String类型数据返回的方法
     * @param data
     * @param isStringData
     * @return
     */
    public static ResultUtil success(Object data, boolean isStringData) {
        ResultUtil resultUtil;
        if (isStringData) {
            resultUtil = success(data);
        }else {
            resultUtil = success((String) data);
        }
        return resultUtil;
    }

    /**
     * 失败的方法
     * @return
     */
    public static ResultUtil failure() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = "failure";
        return resultUtil;
    }

    public static ResultUtil failure(String message) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = message;
        return resultUtil;
    }

    public static ResultUtil failure(String message, Object data) {
        ResultUtil resultUtil = failure(message);
        resultUtil.data = data;
        return resultUtil;
    }

}
